package cloud.seri.auth.service.mapper

import cloud.seri.auth.domain.Dept
import cloud.seri.auth.service.dto.DeptDTO

import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings

/**
 * Mapper for the entity [Dept] and its DTO [DeptDTO].
 */
@Mapper(componentModel = "spring", uses = [])
interface DeptMapper : EntityMapper<DeptDTO, Dept>
{
    @Mappings(
        Mapping(source = "parent.id", target = "parentId")
    )
    override fun toDto(entity: Dept): DeptDTO

    @Mappings(
        Mapping(source = "parentId", target = "parent")
    )
    override fun toEntity(dto: DeptDTO): Dept

    fun fromId(id: String?): Dept?
    {
        if (id == null)
        {
            return null
        }
        val dept = Dept()
        dept.id = id
        return dept
    }
}
